﻿using Autofac;
using KingsSharp.Common.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace CRM.Admin
{
    /// <summary>
    /// 用户cookie数据
    /// </summary>
    public class UserCookies
    {
        /// <summary>
        /// 用户名称
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 用户Id
        /// </summary>
        public Guid UserId { get; set; }

        /// <summary>
        /// 登录帐号
        /// </summary>
        public string LoginCode { get; set; }

    }
    /// <summary>
    /// 系统运行时需要保存的变量集合
    /// </summary>
    public class AppVariable
    {
        /// <summary>
        /// 用户登录信息
        /// </summary>
        public static UserCookies UserData
        {
            get
            {
                if (System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    FormsIdentity id = (FormsIdentity)System.Web.HttpContext.Current.User.Identity;
                    FormsAuthenticationTicket Ticket = id.Ticket;
                    return Ticket.UserData.FromJsonString<UserCookies>();
                }
                return null;
            }
        }

        /// <summary>
        /// 获取autofac mvc的container
        /// </summary>
        public static IContainer IocContainer { get; set; }
    }
}